package com.ericsson.rm.dao;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.ericsson.rm.model.ProjectDetail;
import com.ericsson.rm.vo.ProjectDetailsVO;
@Repository
public class ProjectDtlFromCSVDaoImpl implements ProjectDtlFromCSVDao{
	
	@PersistenceContext
	EntityManager entityManager;
	

	@Override
	@Transactional(propagation=Propagation.REQUIRES_NEW)
	
	public void saveProjectDtls(List<ProjectDetailsVO>  projectDetails_arrylist){
		      
		
		     try{
		      if(projectDetails_arrylist!=null && projectDetails_arrylist.size()>0){
		    	  
		       System.out.println("projectDetails_arrylist:"+projectDetails_arrylist.size());
		    	  for(ProjectDetailsVO projectDetailsVO :  projectDetails_arrylist){
		    		
		    		  ProjectDetail  details = new ProjectDetail();
		    	
		    			details.setNoOfResource(projectDetailsVO.getNo_of_resource());
		    			details.setProjectName(projectDetailsVO.getProjectName());
		    			details.setRegion(projectDetailsVO.getRegion());
		    			details.setProjectEndDate(projectDetailsVO.getProject_end_date());
		    			details.setProjectStartDate(projectDetailsVO.getProject_start_date());
		    			details.setProjectId(projectDetailsVO.getProjectId());
		    			details.setStatus(projectDetailsVO.getStatus());
		    			details.setLocation(projectDetailsVO.getLocation());
		    			details.setProject_manager_signum(projectDetailsVO.getProject_manager_signum());
		    			entityManager.persist(details);
		    			entityManager.flush();
		    			entityManager.close();
		    		 }
		    			
		    	}
		     }
		     
		    catch(Exception e){
		    	 e.printStackTrace();
		    	 
		     }
		    }
		    	  
		    	  
		    	  
 }
		
	
